<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model app\models\Customer */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="customer-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'web_site')->textInput(['maxlength' => true]) ?>

    <div class="form-group field-customer-type required">
        <label class="control-label" for="customer-type">分类</label>
        <select class="form-control" name="Customer[type]">
            <?php
            foreach($cats as $key => $value){
                if(isset($value['child'])){
                    echo '<optgroup label="'.$value['name'].'">';
                    foreach($value['child']  as $k => $v){
                        if($model->type == $k){
                            echo '<option value="'.$k.'" selected = selected>'.$v.'</option>';
                        }else{
                            echo '<option value="'.$k.'">'.$v.'</option>';
                        }

                    }
                    echo '</optgroup>';
                }else{
                    if($model->type == $key){
                        echo '<option value="'.$key.'" selected = selected >'.$value['name'].'</option>';
                    }else{
                        echo '<option value="'.$key.'"  >'.$value['name'].'</option>';
                    }

                }
            }
            ?>
        </select>

        <div class="help-block"></div>
    </div>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? '创建' : '修改', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
